<?php

namespace app\model;

use think\Model;

class OrderLog extends Model
{
    /**
     * 订单日志表
     */

    protected $createTime='create_date';


    public function getSubmitIdAttr($name)
    {
        return [
            'id'=>$name,
            'text'=>(new User)->getIdNickName ($name)
        ];
    }

    public function addDataModel($data)
    {
        return self::create($data);
    }
    /**
     * 通过证书延伸id  查询日志
     * @param $id
     * @return \app\model\OrderLog|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getIdFindData($id)
    {
        return $this->where(['order_company_id'=>$id])->find();
    }

    public function getIdCertificateCodeModel($id,$cer)
    {
        return $this->where(['order_company_id'=>$id,'certificate_code'=>$cer])->select()->toArray ();
    }

    /**
     * 通过证书编号查询日志
     * @param $certificateCode
     * @return array|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCertificateCodeFindDataModel($certificateCode): ?array
    {
        return $this->where (['certificate_code' => $certificateCode])->select ()->toArray ();
    }
    /**
     * 根据id type 查询分类数据
     * @param $id
     * @param $type
     * @return \app\model\OrderLog[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getIdDataModel($id,$type){

        return $this->where(['order_company_id'=>$id,'type'=>$type])->select();
    }

    /**
     * 查询驳回原因
     * @param $cer
     * @return mixed
     */
    public function getRejectModel($id,$cer)
    {
        return $this->where (['order_company_id'=>$id,'certificate_code'=>$cer,'is_reject'=>1])->order('create_date DESC')->value ('content');
    }

    public function getOrderLogModel($id,$cer)
    {
        return $this->where(['order_company_id'=>$id,'certificate_code'=>$cer])->order('create_date DESC')->select ()->toArray ();
    }

}